package com.example.practice.view;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ListView;

import com.example.practice.R;
import com.example.practice.adapter.ExcerciseAdapter_yl;
import com.example.practice.bean.ExercisesBean;

import java.util.ArrayList;
import java.util.List;

public class ExerciseViewYL {
    private ListView lv_list_yl;
    private ExcerciseAdapter_yl adapter_yl;
    private List<ExercisesBean> ebl_yl;
    private Activity mContext_yl;
    private LayoutInflater mInflater_yl;
    private View mCurrentView_yl;
    private String[] title_yl={"第1章 Android基础入门","第2章 Android UI开发","第3章 Android UI开发 ","第4章 Android UI开发","第5章 Android UI开发"};
    private int[] content_yl={5,5,5,4,5};
    private int[] background = {R.drawable.exercises_bg_1,R.drawable.exercises_bg_2,R.drawable.exercises_bg_3,R.drawable.exercises_bg_4,R.drawable.exercises_bg_1};

    /**
     * 构造函数
     */
    public ExerciseViewYL(Activity context){
        mContext_yl=context;
        mInflater_yl=LayoutInflater.from(mContext_yl);
    }

    /**
     * 初始化数据
     */
    private void initData(){
        ebl_yl=new ArrayList<ExercisesBean>();
        for (int i = 0; i < title_yl.length; i++) {
            ExercisesBean bean = new ExercisesBean();
            bean.id= i+1;
            bean.title=title_yl[i];
            bean.content="共计"+content_yl[i]+"题";
            bean.background=background[i];
            ebl_yl.add(bean);
        }
    }

    /**
     * 初始化界面
     */
    private void initView(){
        mCurrentView_yl=mInflater_yl.inflate(R.layout.exercises_view_yl,null);
        lv_list_yl=mCurrentView_yl.findViewById(R.id.lv_exercise_yl);
        adapter_yl=new ExcerciseAdapter_yl(mContext_yl);
        initData();

        adapter_yl.setData(ebl_yl);
        lv_list_yl.setAdapter(adapter_yl);
    }

    /**
     *
     * 创建界面
     */
    private void createView(){
        initView();
    }

    /**
     * 获取当前在导航栏上方显示对应的view
     */
    public View getView(){
        if (mCurrentView_yl==null){
            createView();
        }
        return mCurrentView_yl;
    }

    /**
     *
     * 显示当前导航栏上方所对应的view界面
     */
    public void showView(){
        if (mCurrentView_yl==null){
            createView();
        }
        mCurrentView_yl.setVisibility(View.VISIBLE);
    }
}
